# Makefile : Builds a Foundation class library variant.
#
# This is a part of the Microsoft Foundation Classes C++ library.
# Copyright (C) 1994-1996 WATCOM International Corporation
# All rights reserved.
#
# This source code is only intended as a supplement to the
# Microsoft Foundation Classes Reference and Microsoft
# QuickHelp and/or WinHelp documentation provided with the library.
# See these sources for detailed information regarding the
# Microsoft Foundation Classes product.
#
# Usage: wmake clean        (removes all intermediary files)
#    or: wmake options      (builds one library variant (see below))
# Note that an wmake clean should be performed before building a new variant.
#
# 'Options' are one of each of:
#
#   model=l     (defaults to l)
#       Only large model is supported.
#
#   target=w    (defaults to w)
#       Any of the following targets are accepted: 
#               r (real mode DOS),
#               w (windows).
#
#   debug=1     (defaults to 1)
#       If this item is 1, debugging support is compiled into
#       the library.  If this item is 0, then debugging support
#       is disabled.  Debug support does not include symbolic information.
#
#   symbolic=2  (defaults to 2)
#       If this item is 1, symbolic debugging information is compiled
#       into the library for all object files.  If this item is 0, no
#       symbolic debugging information is compiled into the object files.
#       If this item is 2, symbolic debugging information is compiled
#       into a few selected object files.
#
#   dll=0       (defaults to 0)
#       If this item is 0, then a normal library is generated.
#       If this item is 1, a version of the library suitable
#       for linking into a user DLL is generated.
#       If this item is 2, a stand alone dll version of the library 
#       is generated.
#
#   opt         (defaults to nothing)
#       This allows additional compiler flags to be specified.
#
#   no_pch=0    (defaults to 0)
#       Set this item to override the default use of precompiled headers.
#
#   browse=0    (defaults to 0)
#       Set this option to build the browser database for the MFC
#       library.  By setting browse=1, both the .MBRs and the .DBR
#       files will be built along with the .OBJ and .LIB files that
#       are part of the normal build process.
#
#   The default is to build model=l target=w debug=1 symbolic=2
#

#
# Parameter defaults and validation...
#
!ifndef model
!  ifdef MODEL
model=$+$(MODEL)$-
!  else
model=l
!  endif
!endif
!ifeq model L
model=l
!endif
!ifneq model l
!  error Invalid model specified.
!endif

!ifndef target
!  ifdef TARGET
target=$+$(TARGET)$-
!  else
target=w
!  endif
!endif
!ifeq target W
target=w
!endif
!ifeq target R
target=r
!endif
!ifneq target w
!  ifneq target r
!    error Invalid target specified.
!  endif
!endif

!ifndef debug
!  ifdef DEBUG
debug=$+$(DEBUG)$-
!  else
debug=1
!  endif
!endif
!ifneq debug 0
!  ifneq debug 1
!    error Invalid debug value specified.
!  endif
!endif

!ifndef symbolic
!  ifdef SYMBOLIC
symbolic=$+$(SYMBOLIC)$-
!  else
!    ifeq debug 1
symbolic=2
!    else
symbolic=0
!    endif
!  endif
!endif
!ifneq symbolic 0
!  ifneq symbolic 1
!    ifneq symbolic 2
!      error Invalid symbolic value specified.
!    endif
!  endif
!endif

!ifndef dll
!  ifdef DLL
dll=$+$(DLL)$-
!  else
dll=0
!  endif
!endif
!ifneq dll 0
!  ifneq dll 1
!    ifneq dll 2
!      error Invalid dll value specified.
!    endif
!  endif
!endif

!ifndef no_pch
!  ifdef NO_PCH
no_pch=$+$(NO_PCH)$-
!  else
no_pch=0
!  endif
!endif
!ifneq no_pch 0
!  ifneq no_pch 1
!    error Invalid no_pch value specified.
!  endif
!endif

!ifndef browse
!  ifdef BROWSE
browse=$+$(BROWSE)$-
!  else
browse=0
!  endif
!endif
!ifneq browse 0
!  ifneq browse 1
!    error Invalid browse value specified.
!  endif
!endif

!ifndef opt
!  ifdef OPT
opt=$+$(OPT)$-
!  endif
!endif

#
# set compilation switches
#
cflags=-zq-m$(model) -zmf-ox-w3 $(opt)
aflags=-zq-m$(model) 
rflags=-q -bt=windows -k

!ifeq target w
cflags+= -2-bt=windows
aflags+= -2-bt=windows
!else
cflags+= -bt=dos
aflags+= -bt=dos
!endif

!ifeq debug 1
cflags+= -d_DEBUG
aflags+= -d_DEBUG
dbgsuffix=d
!endif

!ifeq symbolic 1
cflags+= -d2-hw
lflags=debug watcom all
!endif

!ifeq no_pch 0
cflags += -fhq
!endif

!ifeq dll 0
type=c
!ifeq target w
cflags+= -zws
!endif
!else
!  ifeq dll 1
cflags+= -bd-zu -d_USRDLL -d_WINDLL
type=d
dllsuffix=.dll
!  else
!    ifeq dll 2
cflags+= -d_WINDLL -d_AFXDLL
type=e
dllsuffix=$(subdir).dll
!    endif
!  endif
!endif

#
# set subdirectory and library names
#
dir=_$(model)$(target)$(dbgsuffix)$(dllsuffix)
!ifneq dll 2
targlib=$(model)afx$(type)$(target)$(dbgsuffix)
!endif

#
# setup magic build switches
#
zl_sw=-zl
no_zl_sw=
!ifeq dll 2
sw_zl_opts_dumpinit=no_
sw_zl_opts_dllinit=no_
sw_zl_opts_dllole=no_
sw_zl_opts_dlldb=no_
sw_zl_opts_dllnet=no_
!else
sw_zl_opts_winmain=no_
!endif

!ifeq dll 2
bd_sw=-bd-zu
no_bd_sw=-zws
sw_bd_opts_afxdll=no_
sw_bd_opts_dumpinit=no_
sw_bd_opts_dumpout=no_
sw_bd_opts_afxasert=no_
sw_bd_opts_afxmem=no_
sw_bd_opts_afxabort=no_

sw_so_opts_dumpinit=-d_STATICOBJ
sw_so_opts_dumpout=-d_STATICOBJ
sw_so_opts_afxasert=-d_STATICOBJ
sw_so_opts_afxmem=-d_STATICOBJ
sw_so_opts_afxabort=-d_STATICOBJ
!endif

!ifeq symbolic 2
sw_d2_opts_afxmem=-d2-hw
sw_d2_opts_winmain=-d2-hw
sw_d2_opts_wincore=-d2-hw
sw_d2_opts_appcore=-d2-hw
!endif

!ifeq browse 1
cflags += -db
sw_db_opts_objcore=-db
!endif


.extensions:
.extensions: .exe .dll .lib .obj .res .rc .cpp .asm

.before
    set include=$(%watcom)\h;$(%watcom)\h\win;
    
.asm.obj:
    *wasm $[@ $(aflags) -fo=$(dir)\$^.
    
.obj: $(dir)
.cpp.obj:
    *wpp $[@ $(cflags) $($(sw_zl_opts_$^&)zl_sw) $($(sw_bd_opts_$^&)bd_sw) $(sw_d2_opts_$^&) $(sw_so_opts_$^&) $(sw_db_opts_$^&) -fo=$(dir)\$^.
!ifeq browse 1
    @if exist $(obj)\$^*.mbr wbrg quiet database $(targdbr) file $(obj)\$^*.mbr
    @if exist $(obj)\$^*.mbr @erase $(obj)\$^*.mbr > nul
!endif
    
object = &
    objcore.obj &
    except.obj &
    afxver.obj &
    validadd.obj &
    dumpcont.obj &
    dumpflt.obj &
    arccore.obj &
    arcobj.obj &
    arcex.obj

objdiag = &
    dumpinit.obj &
    dumpout.obj &
    afxasert.obj &
    afxmem.obj &
    afxabort.obj

files = &
    filecore.obj &
    filetxt.obj &
    filemem.obj &
    filex.obj &
    filest.obj

collections1 = &
    array_b.obj &
    array_d.obj &
    array_p.obj &
    array_o.obj &
    array_s.obj &
    array_u.obj &
    array_w.obj &
    list_o.obj &
    list_p.obj &
    list_s.obj

collections2 = &
    map_pp.obj &
    map_pw.obj &
    map_so.obj &
    map_sp.obj &
    map_ss.obj &
    map_wo.obj &
    map_wp.obj &
    plex.obj

misc = &
    strcore1.obj &
    strcore2.obj &
    strex.obj &
    timecore.obj

windows = &
    wincore.obj &
    winfrm.obj &
    winfrmx.obj &
    winmdi.obj &
    winhand.obj &
    winmain.obj &
    barcore.obj &
    bartool.obj &
    bardlg.obj &
    dcprev.obj &
    dcmeta.obj &
    trckrect.obj &
    fileshrd.obj

dialog = &
    dlgcore.obj &
    dlgdata.obj &
    dlgfloat.obj &
    winctrl.obj &
    winbtn.obj &
    penctrl.obj &
    dlgfile.obj &
    dlgprnt.obj &
    dlgclr.obj &
    dlgfnt.obj &
    dlgfr.obj &
    dlgprop.obj

winmisc = &
    wingdi.obj &
    wingdix.obj &
    winstr.obj &
    winmenu.obj &
    auxdata.obj &
    afxtrace.obj &
    winutil.obj

docview = &
    cmdtarg.obj &
    doccore.obj &
    doctempl.obj &
    docsingl.obj &
    docmulti.obj &
    docmapi.obj &
    viewcore.obj &
    viewprnt.obj &
    winsplit.obj &
    viewscrl.obj &
    viewform.obj &
    viewedit.obj &
    viewprev.obj

application = &
    appcore.obj &
    appinit.obj &
    appterm.obj &
    appui.obj &
    appui2.obj &
    appgray.obj &
    appdlg.obj &
    appprnt.obj &
    apphelp.obj &
    apphelpx.obj &
    appdata.obj

db = &
    dbcore.obj &
    dbrfx.obj &
    dbflt.obj &
    dbview.obj

sockets = &
    sockcore.obj

olereq = &
    olelock1.obj &
    olelock2.obj &
    oledata.obj

oledll = &
    oleinit.obj &
    olebar.obj &
    olecli1.obj &
    olecli2.obj &
    olecli3.obj &
    oledobj1.obj &
    oledobj2.obj &
    oledisp1.obj &
    oledisp2.obj &
    oledlgs1.obj &
    oledlgs2.obj &
    oledoc1.obj &
    oledoc2.obj &
    oledrop1.obj &
    oledrop2.obj &
    olemsgf.obj &
    oleenum.obj &
    olefact.obj &
    oleipfrm.obj &
    olelink.obj &
    olemisc.obj &
    olestrm.obj &
    olesvr1.obj &
    olesvr2.obj &
    olereg.obj &
    oletsvr.obj &
    oleui1.obj &
    oleui2.obj &
    oleunk.obj

!ifeq dll 1
olereq += &
    oledll.obj
!endif

ole = &
    $(olereq) &
    $(oledll) &
    olecall_.obj

!ifeq debug 1
inlines = &
    afxinl1.obj
!ifeq target w
inlines += &
    afxinl2.obj &
    afxinl3.obj
!endif
!endif

!ifndef objs
objs = &
    $(object) &
    $(objdiag) &
    $(inlines) &
    $(files) &
    $(collections1) &
    $(collections2) &
    $(misc)
    
!ifeq target w
objs += &
    $(windows) &
    $(dialog) &
    $(winmisc) &
    $(docview) &
    $(application) &
    $(db) &
    $(sockets) &
    $(ole)
!endif
!endif

goals = subdirectory
!ifeq dll 2
goals += $(targdll).lib
!  ifeq browse 1
targdbr = $(targdll).dbr
!  endif
!else
goals += $(targlib).lib
!  ifeq browse 1
targdbr = $(targlib).dbr
!  endif
!endif

all : $(goals) .symbolic
    @%null
    
subdirectory : .symbolic
    @-if not exist $(dir) mkdir $(dir)
    
!ifeq dll 2
$(targdll).lib : $(targdll).dll $(staticobjs)
    %create tmp.lbc
    @for %i in ( $(staticobjs) ) do @%append tmp.lbc +$(dir)\%i
    wlib /q /b /c /n /p=16 $^@ @$(targdll).lbc @tmp.lbc
!else
$(targlib).lib : $(objs)
    %create tmp.lbc
    @for %i in ( $(objs) ) do @%append tmp.lbc +$(dir)\%i
    wlib /q /b /c /n /p=512 $^@ @tmp.lbc
!endif

!ifeq dll 2
$(targdll).dll : $(objs) $(targdll).res $(targdll).lnk
    wlink $(lflags) name $^@ @$(targdll).lnk @$(targdll).def
    wrc $(rflags) $(targdll).res $^@
    
$(targdll).lnk : $(__MAKEFILES__)
    %create $^@
    @%append $^@ system windows_dll memory font
    @%append $^@ option map
    @%append $^@ reference __clib_WEP_
    @%append $^@ disable 121
    @for %i in ( $(objs) ) do @%append $^@ file $(dir)\%i
    
!ifdef res
$(targdll).res : $(res).rc
    wrc $(rflags) -fo=$^. -r $]@ -i$(%watcom)\samples\mfc\v252
!endif
!endif

clean global : .symbolic
    @if exist $(dir)\*.obj erase $(dir)\*.obj >nul
    @if exist *.pch erase *.pch >nul
    @if exist *.dll erase *.dll >nul
    @if exist *.lib erase *.lib >nul
    @if exist *.map erase *.map >nul
    @if exist *.obj erase *.obj >nul
    @if exist *.res erase *.res >nul
    @if exist *.err erase *.err >nul
    @if exist *.lnk erase *.lnk >nul
    @-rmdir $(dir) >nul
